package tech.daoxuan.web.validator;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import tech.daoxuan.web.service.HelloService;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * 在这个实现校验的类中，可以注入接口
 */
public class MyConstraintValidator implements ConstraintValidator<MyConstraint, Object> {
    Logger logger = LoggerFactory.getLogger(MyConstraintValidator.class);
//        @Autowired

    @Autowired
    private HelloService helloService;

    @Override
    public void initialize(MyConstraint constraintAnnotation) {
        logger.info("MyConstraint is initialize");


    }

    /**
     * 真正的校验逻辑
     *
     * @param value
     * @param context
     * @return
     */
    @Override
    public boolean isValid(Object value, ConstraintValidatorContext context) {
        String hello = helloService.hello();
        logger.info(hello+"------------");
        logger.info("自定义校验开始校验。。。。");
        return false;
    }
}
